package com.sgb.kjwl.viewmodel.enterprise;

import com.sgb.kjwl.AppConstant;
import com.sgb.kjwl.api.APIManager;
import com.sgb.kjwl.api.EnterpriseAPIManager;
import com.sgb.kjwl.model.entity.enterprise.IpPickSelectEntity;
import com.sgb.kjwl.model.entity.enterprise.TeamChangeEntity;
import com.sgb.kjwl.model.entity.user.AddressEntity;
import com.swgk.core.base.model.entity.ListResponse;
import com.sgb.kjwl.view.ui.activity.enterprise.ProfessionalTeamChangeActivity;
import com.swgk.core.base.model.entity.BaseEntity;
import com.swgk.core.dialog.DialogHelper;
import com.swgk.core.util.MLog;
import com.swgk.core.util.MToast;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class ProfessionalTeamChangeModel{
    ProfessionalTeamChangeActivity professionalTeamChangeActivity;
    private int pageNum = 1;
    IpPickSelectEntity entity1 = new IpPickSelectEntity("", "不限", "", "", "", "","");


    public ProfessionalTeamChangeModel(ProfessionalTeamChangeActivity professionalTeamChangeActivity) {
        this.professionalTeamChangeActivity = professionalTeamChangeActivity;
    }

    /**
     * 商标列表查询
     */
    public void getTeamQueryList(Map<String,Object> map) {
        MLog.e("asgdyhuij",map+"");
        MLog.e("asgdyhuij",map+"");
        DialogHelper.showProgressDialog(professionalTeamChangeActivity, null, "数据加载中...", 0, false, null).setCanceledOnTouchOutside(false);
        EnterpriseAPIManager.getInstance().getEnterpriseAPI().getTeamQueryList(map).enqueue(new Callback<BaseEntity<ListResponse<List<TeamChangeEntity>>>>() {
            @Override
            public void onResponse(Call<BaseEntity<ListResponse<List<TeamChangeEntity>>>> call, Response<BaseEntity<ListResponse<List<TeamChangeEntity>>>> response) {
                DialogHelper.dismissProgressDialog();
                if (response.body() == null || response.body().getData() == null) {
                    return;
                }
                if (response.body().getState().equals(APIManager.RESPONSE_OK)) {
                   // professionalTeamChangeActivity.showList(response.body().getData().getList());
                } else {
                    MToast.showToast(professionalTeamChangeActivity, response.body().getMsg());
                }
            }

            @Override
            public void onFailure(Call<BaseEntity<ListResponse<List<TeamChangeEntity>>>> call, Throwable t) {
                DialogHelper.dismissProgressDialog();
            }
        });
    }

    /*
     * 获取团队类别 本地写入数据
     */
    public void getTeamType() {
        IpPickSelectEntity entity1 = new IpPickSelectEntity("", "不限", "", "", "", "", "");
        IpPickSelectEntity entity2 = new IpPickSelectEntity("0", "个人", "", "", "", "", "");
        IpPickSelectEntity entity3 = new IpPickSelectEntity("1", "企业", "", "", "", "", "");
        List<IpPickSelectEntity> teamType = new ArrayList<>();
        teamType.add(entity1);
        teamType.add(entity2);
        teamType.add(entity3);
      //  professionalTeamChangeActivity.showTypePopWindow(teamType);
    }

    /**
     * 获取服务城市
     */
    public void getServiceCity() {
        DialogHelper.showProgressDialog(professionalTeamChangeActivity, null, "数据加载中...", 0, false, null).setCanceledOnTouchOutside(false);
        EnterpriseAPIManager.getInstance().getGoodsAPI().getCityList().enqueue(new Callback<BaseEntity<List<AddressEntity<List<AddressEntity<List<AddressEntity>>>>>>>() {
            @Override
            public void onResponse(Call<BaseEntity<List<AddressEntity<List<AddressEntity<List<AddressEntity>>>>>>> call, Response<BaseEntity<List<AddressEntity<List<AddressEntity<List<AddressEntity>>>>>>> response) {
                DialogHelper.dismissProgressDialog();
                if (response.body() == null || response.body().getData() == null) {
                    MToast.showToast(professionalTeamChangeActivity, "暂无数据");
                    return;
                }
                if (response.body().getState().equals(APIManager.RESPONSE_OK)) {
                    List<AddressEntity<List<AddressEntity<List<AddressEntity>>>>> list = new ArrayList<>();
                    list.addAll(response.body().getData());
                    AddressEntity entity = new AddressEntity();
                    entity.setNo("");
                    entity.setName("全国");
                    list.add(0, entity);
              //      professionalTeamChangeActivity.showCityPopWindow2(list);
                } else {
                    MToast.showToast(professionalTeamChangeActivity, response.body().getMsg());
                }
            }

            @Override
            public void onFailure(Call<BaseEntity<List<AddressEntity<List<AddressEntity<List<AddressEntity>>>>>>> call, Throwable t) {
                DialogHelper.dismissProgressDialog();
                MLog.d(AppConstant.API_LOG, "error " + t.getMessage());
            }
        });
    }

    /**
     * 经营类型
     */
    public void getServiceType() {
        DialogHelper.showProgressDialog(professionalTeamChangeActivity, null, "数据加载中...", 0, false, null).setCanceledOnTouchOutside(false);
        EnterpriseAPIManager.getInstance().getGoodsAPI().serviceType().enqueue(new Callback<BaseEntity<List<IpPickSelectEntity>>>() {
            @Override
            public void onResponse(Call<BaseEntity<List<IpPickSelectEntity>>> call, Response<BaseEntity<List<IpPickSelectEntity>>> response) {
                DialogHelper.dismissProgressDialog();
                if (response.body() == null || response.body().getData() == null) {
                    MToast.showToast(professionalTeamChangeActivity, "暂无数据");
                    return;
                }
                if (response.body().getState().equals(APIManager.RESPONSE_OK)) {
                    List<IpPickSelectEntity> list = new ArrayList<>();
                   // list.add(0,entity1);
                    list.addAll(response.body().getData());
                    professionalTeamChangeActivity.getAllCategory(list);
                } else {
                    MToast.showToast(professionalTeamChangeActivity, response.body().getMsg());
                }
            }

            @Override
            public void onFailure(Call<BaseEntity<List<IpPickSelectEntity>>> call, Throwable t) {
                DialogHelper.dismissProgressDialog();
                MLog.d(AppConstant.API_LOG, "error " + t.getMessage());
            }
        });
    }
}